#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2014年10月13日

@author: chenyongbing
'''
from django import forms
import datetime
from django.forms.util import ErrorList
from localConfig import LocalConfig
myLocalConfig = LocalConfig()
class DivErrorList(ErrorList):
    def __unicode__(self):
        return self.as_text()

    def as_divs(self):
        if not self:
            return u''
        return '<div class="errorList">%s</div>' % ''.join(['<div class="error">%s</div>' %e for e in self])

class RssiForm(forms.Form):
    '''
    classdocs
    '''
    my_int_default_errors = {
        'required': '该字段不能为空',
        'invalid': '输入正确的数字类型'
    }
    my_email_default_errors = {
        'required': '该字段不能为空',
        'invalid': '输入正确的邮箱类型'
    }
    my_date_default_errors = {
        'required': '该字段不能为空',
        'invalid': '输入正确的日期类型yyyy-mm-dd'
    }
    groupChoices = (('compname',u'公司名'),('compid',u'公司ID'),('shopname',u'门店名'),('shopid',u'门店ID'),('device',u'设备'))
    typeChoices = (('detail',u'明细'),('stat',u'统计'))
    simChoices = (('hour',u'小时'),('day',u'天'))
    showChoices = (('customer',u'顾客'),('walkby',u'路人'),('employee',u'员工'))
    groupType = forms.ChoiceField(choices=groupChoices,required=True,label=u'编号类型')
    groups = forms.CharField(widget=forms.Textarea(attrs={'placeholder':"多个内容请换行",'onclick':"if(value==defaultValue){value='';this.style.color='#000'}",'onBlur':"if(!value){value=defaultValue;this.style.color='#999'}"}),label=u'编号列表',required=True)
    
    customer_rssi_min = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.customer_rssi_min}),label=u'入店判断rssi范围最小值(db)',min_value=-100,max_value=0,error_messages=my_int_default_errors)
    customer_rssi_max = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.customer_rssi_max}),label=u'入店判断rssi范围最大值(db)',min_value=-100,max_value=0,error_messages=my_int_default_errors)
    flow_rssi_max = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.flow_rssi_max}),min_value=-100,max_value=0,label=u'客流判断rssi范围最大值(db)',error_messages=my_int_default_errors)
    flow_rssi_min = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.flow_rssi_min}),min_value=-100,max_value=0,label=u'客流判断rssi范围最小值(db)',error_messages=my_int_default_errors)
    startTime = forms.DateField(widget=forms.TextInput(attrs={'placeholder':"2014-09-11",'class':'form-control'}),input_formats=(("%Y-%m-%d"),),label=u"开始时间",error_messages=my_date_default_errors)
    endTime = forms.DateField(widget=forms.TextInput(attrs={'placeholder':"2014-09-11",'class':'form-control'}),input_formats=(("%Y-%m-%d"),),label=u"结束时间",error_messages=my_date_default_errors)
    
    opening_weekday = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'工作日营业时间',required=True,initial=myLocalConfig.opening_weekday)
    opening_weekend = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'周末营业时间',required=True,initial=myLocalConfig.opening_weekend)
    walkby_min = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.walkby_min}),min_value=0,max_value=100,label=u'顾客判断时长最小值(分)',error_messages=my_int_default_errors)
    walkby_max = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.walkby_max}),min_value=0,max_value=100,label=u'顾客判断时长最小值(分)',error_messages=my_int_default_errors)
    #exportType = forms.ChoiceField(choices=typeChoices,initial='stat',label=u'导出数据类型')
    #simType = forms.ChoiceField(choices=simChoices,initial='day',label=u'计算类型')
    #showType = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(),choices=showChoices,initial=showChoices[0],label=u'角色选择')
    email = forms.EmailField(label=u'邮箱',error_messages=my_email_default_errors)
    
    
class ShowRssiForm(RssiForm):
    groupChoices = (('compname',u'公司名'),('compid',u'公司ID'),('shopname',u'门店名'),('shopid',u'门店ID'),('device',u'设备'))
    typeChoices = (('detail',u'明细'),('stat',u'统计'))
    simChoices = (('hour',u'小时'),('day',u'天'))
    showChoices = (('customer',u'顾客'),('walkby',u'路人'),('employee',u'员工'))
    runChoices = (('run',u'运行'),('stop',u'停止'))
    groupType = forms.ChoiceField(widget=forms.RadioSelect(attrs={'class':'form-control','disabled':'disabled'}),choices=groupChoices,required=False,label=u'编号类型')
    groups = forms.CharField(widget=forms.Textarea(attrs={'placeholder':"多个内容请换行",'onclick':"if(value==defaultValue){value='';this.style.color='#000'}",'onBlur':"if(!value){value=defaultValue;this.style.color='#999'}",'disabled':'disabled'}),label=u'编号列表',required=False)
    
    customer_rssi_min = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.customer_rssi_max,'disabled':'disabled'}),label=u'入店判断rssi范围最小值(db)',min_value=-100,max_value=0,)
    customer_rssi_max = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.customer_rssi_min,'disabled':'disabled'}),label=u'入店判断rssi范围最大值(db)',min_value=-100,max_value=0,)
    flow_rssi_max = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.flow_rssi_max,'disabled':'disabled'}),min_value=-100,max_value=0,label=u'客流判断rssi范围最大值(db)')
    flow_rssi_min = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':'%s'%myLocalConfig.flow_rssi_min,'disabled':'disabled'}),min_value=-100,max_value=0,label=u'客流判断rssi范围最小值(db)')
    startTime = forms.DateField(widget=forms.TextInput(attrs={'placeholder':"2014-09-11",'class':'form-control','disabled':'disabled'}),input_formats=(("%Y-%m-%d"),),label=u"开始时间")
    endTime = forms.DateField(widget=forms.TextInput(attrs={'placeholder':"2014-09-11",'class':'form-control','disabled':'disabled'}),input_formats=(("%Y-%m-%d"),),label=u"结束时间")
    
    opening_weekday = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control','disabled':'disabled'}),label=u'工作日营业时间',required=False,initial=myLocalConfig.opening_weekday)
    opening_weekend = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control','disabled':'disabled'}),label=u'周末营业时间',required=False,initial=myLocalConfig.opening_weekend)
    walkby_min = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':myLocalConfig.walkby_min,'disabled':'disabled'}),min_value=0,max_value=100,label=u'顾客判断时长最小值(分)')
    walkby_max = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control','value':myLocalConfig.walkby_max,'disabled':'disabled'}),min_value=0,max_value=100,label=u'顾客判断时长最小值(分)')
    #exportType = forms.ChoiceField(choices=typeChoices,initial='stat',label=u'导出数据类型')
    #simType = forms.ChoiceField(choices=simChoices,initial='day',label=u'计算类型')
    #showType = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(),choices=showChoices,initial=showChoices[0],label=u'角色选择')
    email = forms.EmailField(label=u'邮箱',widget=forms.TextInput(attrs={'class':'form-control','disabled':'disabled'}))


class ExpectRssiForm(forms.Form):
    shopGroups = (('tesing','tesing'),)
    walkbyGroups = (('1','1分钟'),('2','2分钟'))
    shop_group =forms.ChoiceField(choices=shopGroups,required=False,label=u'门店')
    
    real_data = forms.CharField(widget=forms.Textarea(attrs={'placeholder':"日期,入店量,客流量\n日期,入店量,客流量",'onclick':"if(value==defaultValue){value='';this.style.color='#000'}",'onBlur':"if(!value){value=defaultValue;this.style.color='#999'}"}),label=u'门店数据',required=False)
    f = forms.IntegerField(widget=forms.TextInput(attrs={'placeholder':"100",'class':'form-control'}),min_value=0,max_value=100,label=u'误差系数(0-100)')
    opening_weekday = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'工作日营业时间',required=False,initial=myLocalConfig.opening_weekday)
    opening_weekend = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'周末营业时间',required=False,initial=myLocalConfig.opening_weekend)
    walkby_time = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(attrs={'class':'form-control'}),choices=walkbyGroups,initial='1',required=False,label=u'入店时长选择')
 
 
class ExpectRssiForm2(forms.Form):
    comps = groups = (('tesing','tesing'),)
    walkbyGroups = (('0','0秒'),('1','1秒'),('15','15秒'),('30','30秒'),('45','45秒'),('60','1分钟'),('120','2分钟'))
    comp_group =forms.ChoiceField(choices=comps,required=False,label=u'公司')
    shop_group =forms.ChoiceField(choices=groups,required=False,label=u'门店')
    startTime = forms.DateField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'开始日期',initial=datetime.date.today()-datetime.timedelta(31))
    endTime = forms.DateField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'结束日期',initial=datetime.date.today()-datetime.timedelta(1))
    customer_weekday_avg_cnt = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control'}),min_value=0,max_value=99999,label=u'工作日平均入店人次')
    customer_weekend_avg_cnt = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control'}),min_value=0,max_value=99999,label=u'周末平均入店人次')
    customer_min_rssi = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control'}),min_value=-99,max_value=0,label=u'入店最小rssi')
    customer_max_rssi = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control'}),min_value=-99,max_value=0,label=u'入店最大rssi')
    wifi_open_rate = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'wifi打开率',required=False,initial=70)
    
    opening_weekday = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'工作日营业时间',required=False,initial=myLocalConfig.opening_weekday)
    opening_weekend = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'周末营业时间',required=False,initial=myLocalConfig.opening_weekend)
    walkby_time = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(),choices=walkbyGroups,initial='1',required=False,label=u'入店时长选择')


 
class SearchRssiForm(forms.Form):
    comps=groups = (('tesing','tesing'),)
    company =forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('company','请选择公司'),),required=False,label=u'公司')
    group =forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('group','请选择门店'),),required=False,label=u'门店')
    walkbyGroups = (('0','0秒'),('1','1秒'),('15','15秒'),('30','30秒'),('45','45秒'),('60','1分钟'),('120','2分钟'))
    startTime = forms.DateField(widget=forms.TextInput(attrs={'placeholder':"2014-09-11",'class':'form-control'}),input_formats=(("%Y-%m-%d"),),label=u"开始时间")
    endTime = forms.DateField(widget=forms.TextInput(attrs={'placeholder':"2014-09-11",'class':'form-control'}),input_formats=(("%Y-%m-%d"),),label=u"结束时间")
    
    #shop_group =forms.ChoiceField(choices=shopGroups,required=False,label=u'门店')
    opening_weekday = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'工作日营业时间',required=False,initial=myLocalConfig.opening_weekday)
    opening_weekend = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'周末营业时间',required=False,initial=myLocalConfig.opening_weekend)
    walkby_time = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(),choices=walkbyGroups,initial='1',required=False,label=u'入店时长选择')
    count_type = forms.ChoiceField(choices=(('0','人次'),('1','人数')),initial='0',required=False,label=u'人次/人数')
    
    
    
class SearchEmployeeRssiForm(forms.Form):
    company = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('company','请选择公司'),),label=u'公司')
    group = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('group','请选择门店'),),label=u'门店')
    startTime = forms.DateField(input_formats=(("%Y-%m-%d"),),label=u"开始时间",required=False)
    endTime = forms.DateField(input_formats=(("%Y-%m-%d"),),label=u"结束时间",required=False)
    excluding = forms.IntegerField(widget=forms.TextInput(attrs={'class':'form-control'}),label=u'剔除比例(%)',required=True,initial='20',min_value=0,max_value=100)
    
    
    
if __name__ == '__main__':
    pass